package com.kk.demo.unsface.two.unsafeList2;

import java.util.Random;

import com.kk.demo.unsface.two.unsafelist.MycatRecord;

/**
 * Desc:
 * <p/>Date: 2016/11/27
 * <br/>Time: 21:04
 * <br/>User: gaozhiwen
 */
public class UnsafeArrayListTest {
    public static void main(String[] args) {
        // HotSpotDiagnostic hsd = new HotSpotDiagnostic();
        // hsd.getDiagnosticOptions().stream().forEach(option ->
        // System.out.println(option.getName()));
        // System.out.println();
        // VMOption vmo = hsd.getVMOption("UseCompressedOops");
        // System.out.println(vmo.getName() + " " + vmo.getValue());

        long time = System.currentTimeMillis();
        int size = 10000000;
        UnsafeArrayList<MycatRecord> list = new UnsafeArrayList<MycatRecord>(size, MycatRecord.class);

        Random random = new Random();

        MycatRecord record = new MycatRecord();
        for (int i = 0; i < size; i++) {
            record.id = i + 1;
            record.col1 = random.nextInt(size);
            // record.col1 = size - i;
            // record.col1 = i;
            record.col2 = (short) random.nextInt(10);
            list.add(i, record);
            // System.out.println(record);
        }
        System.out.println("堆外创建耗时:" + (System.currentTimeMillis() - time) + " ms");

        list.sort("col1");

        // for (int i = 0; i < size; i++) {
        // System.out.println(list.get(i));
        // }
        System.out.println("堆外创建+排序耗时:" + (System.currentTimeMillis() - time) + " ms");
    }
}
